package cn.wolfcode.trip.base.domain;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public class Region extends BaseDomain {
    public static final Integer STATE_DISABLE = -1;//禁用
    public static final Integer STATE_COMMON = 0;//默认
    public static final Integer STATE_HOT = 1;//推荐

    private String name;

    private Region parent;

    private Integer state = STATE_COMMON;

    public Map<String, Object> toTreeMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("text", name);
        map.put("lazyLoad", true);
        if (state == 1) {
            map.put("tags", new String[]{"HOT"});
        }
        return map;
    }

    public String getJson() {
        //共享给按钮的json数据
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("state", state);
        map.put("name", name);
        //如果不是根地区才封装父地区的属性
        if (parent != null) {
            map.put("parentName", parent.getName());
            map.put("parentId", parent.getId());
        }
        return JSON.toJSONString(map);
    }

}